#pragma once

#include <vgraph>

class StateContext
{
public:
	enum {
		BOUNDBOX_CHANGED=0x01,
		SELECTION_CHANGED=0x02,
		ACTIVE_TARGET_CHANGED=0x04
	};

	static StateContext* Null() 
	{
		static StateContext null;
		return &null;
	}

	StateContext()
	{
	}
	StateContext(uint32 activeTarget,const Rect& boundBox=Rect())
	{
		m_boundBox = boundBox;
		m_activeTarget = activeTarget;
	}
	StateContext(uint32 activeTarget,const objectarray& selection,const Rect& boundBox=Rect())
	{
		m_selection = selection;
		m_boundBox = boundBox;
		m_activeTarget = activeTarget;
	}
	const objectarray& GetSelection() const 
	{
		return m_selection;
	}
	const Rect& GetBoundbox() const 
	{
		return m_boundBox;
	}
	void Select(const objectarray& objs)
	{
		_flag |= SELECTION_CHANGED;
		m_selection=objs;
	}
	void Select(IObject* obj)
	{
		_flag |= SELECTION_CHANGED;
		m_selection.push_back(obj);
	}
	void UnionBoundbox(const Rect& rect) 
	{
		_flag |= BOUNDBOX_CHANGED;
		m_boundBox.Union(rect);
	}
	void SetBoundbox(const Rect& rect) 
	{
		_flag |= BOUNDBOX_CHANGED;
		m_boundBox = rect;
	}
	uint32 GetactiveTarget() const 
	{
		return m_activeTarget;
	}
	void SetActiveTarget(uint32 activeTarget) 
	{
		_flag |= ACTIVE_TARGET_CHANGED;
		m_activeTarget = activeTarget;
	}
	bool IsBoundboxChanged() const {return (_flag&BOUNDBOX_CHANGED)==BOUNDBOX_CHANGED;}
	bool IsSelectionChanged() const {return (_flag&SELECTION_CHANGED)==SELECTION_CHANGED;}
	bool IsActiveTargetChanged() const {return (_flag&ACTIVE_TARGET_CHANGED)==ACTIVE_TARGET_CHANGED;}

	void SetRoot(IObject* root){m_root = root;}
	IObject* GetRoot() const {return m_root;}

private:
	Rect m_boundBox;
	objectarray m_selection;
	uint32 m_activeTarget;
	IObject* m_root;

	uint32 _flag;
};